#include <cassert>
#include <vector>
#include <algorithm>
#include<iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <map>
#include <cstdio>
using namespace std;
pair<int, vector<int>> knapsack(int N, int C, vector<long long>& wt, vector<long long>& val) {
    assert(N == wt.size());
    // base case 已初始化
    vector<int> dp(C+1, 0);
    vector<vector<bool>> selected(N+1, vector<bool>(C+1, false));

    for (int i = 0; i <= C; i++) {
        dp[i] = 0;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = C; j >= wt[i-1]; j--) {
            int include = dp[j - wt[i-1]] + val[i-1];
            if (include > dp[j]) {
                dp[j] = include;
                selected[i][j] = true;  // 标记选择当前物品
            }
        }
    }
    // 回溯重建选择的物品序列
    vector<int> items;
    int remaining = C;
    for (int i = N; i >= 1; i--) {
        if (remaining >= wt[i-1] && selected[i][remaining]) {
            items.push_back(i);  // 记录物品编号（1-based）
            remaining -= wt[i-1];
        }
    }
    reverse(items.begin(), items.end());  // 反转得到正序
    
    return {dp[C], items};
}
int main() {
    int N, C;
    cin >> N >> C;
    vector<long long> wt(N), val(N);
    for (int i = 0; i < N; i++) {
        cin >> val[i] >> wt[i];
    }
    auto start = chrono::high_resolution_clock::now(); //开始计时
    auto result = knapsack(N, C, wt, val);
    cout << result.first << endl;  // 输出最大价值
    for (int item : result.second) {
        cout << item << " ";  // 输出选择的物品编号
    }
    cout << endl;
    auto end = chrono::high_resolution_clock::now();
    auto duration = chrono::duration_cast<std::chrono::microseconds>(end - start);
    double time_ms = duration.count() / 1000.0;
    printf("%fms\n",time_ms);
    return 0;
}